package DataStructure.TreeNode;

/**
 *  拓展 二叉树数据结构的前序遍历求树的深度
 */
class TreeNodes {
    public static void main(String[] args) {
        TreeNode tree1 = new TreeNode(1);
        tree1.left = new TreeNode(2);
        tree1.right = new TreeNode(3);
        tree1.left.left = new TreeNode(4);
        tree1.left.left.left = new TreeNode(5);
        tree1.left.left.right = new TreeNode(6);
        System.out.println(tree1.left.left.right);
        tree1.maximum_depth(tree1, 1);
        System.out.println(tree1.answer);
    }
}
class TreeNode {
    TreeNode root ;
    TreeNode left;
    TreeNode right;
    int num;

    public int answer;

    public TreeNode(int num) {
        this.num = num;
    }
    public String toString() {
        return "["+num+"]";
    }

    public void maximum_depth(TreeNode root, int depth) {
        if(root == null) {
            return;
        }
        if(root.left == null && root.right == null) {
            answer = Math.max(answer, depth);
        }
        maximum_depth(root.left, depth+1);
        maximum_depth(root.right, depth+1);
    }
}